<template>
  <div id="app">
    <!-- uname<input type="text" name="uname" v-model="form.uname" required />
    <br />
    password<input
      type="text"
      name="password"
      v-model="form.password"
      required
    />
    <br />
    <input type="file" name="avatar123" @change="getFile" />
    <br />
    <button @click="load">load</button>-->
    <form-test />
  </div>
</template>

<script>
import request from "./util/request";
import formTest from "./components/formTest.vue";
export default {
  name: "App",
  data() {
    return {
      df: null,
      form: {
        uname: "601271628",
        password: "lcx123",
      },
    };
  },
  components: {
    formTest,
  },
  methods: {
    getFile(e) {
      this.df = new FormData();
      this.df.append("avatar123", e.target.files[0]); //图片
    },
    load() {
      //放入非图片数据
      Object.keys(this.form).forEach((key) => {
        this.df.append(key, this.form[key]);
      });
      // for (var arr of this.df.entries()) {
      //   console.log(arr);
      // }
      request({
        method: "post",
        url: "/loadImg",
        data: this.df,
      }).then(
        (res) => {
          console.log(res.data);
        },
        (err) => {
          console.warn(err);
        }
      );
    },
  },
};
</script>

<style>
</style>
